package com.cnswhy.cloud.server.system.service.impl;


import com.cnswhy.cloud.common.core.mybatis.conditions.Wraps;
import com.cnswhy.cloud.common.core.utils.BeanPlusUtil;
import com.cnswhy.cloud.server.system.dao.SystemRoleMapper;
import com.cnswhy.cloud.server.system.dto.SystemRoleSaveDTO;
import com.cnswhy.cloud.server.system.entity.SystemRole;
import com.cnswhy.cloud.server.system.service.SystemRoleService;
import com.cnswhy.cloud.common.core.base.service.SuperServiceImpl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 业务实现类
 * 角色
 * </p>
 *
 * @author cnswhy
 * @date 2020-10-13
 */
@Slf4j
@Service

public class SystemRoleServiceImpl extends SuperServiceImpl<SystemRoleMapper, SystemRole> implements SystemRoleService {
    @Override
    public Boolean check(String code) {
        return super.count(Wraps.<SystemRole>lbQ().eq(SystemRole::getCode, code)) > 0;
    }

    /**
     * 1，保存角色
     * 2，保存 与组织的关系
     *
     * @param data
     * @param userId 用户id
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void saveRole(SystemRoleSaveDTO data, Long userId) {
        SystemRole role = BeanPlusUtil.toBean(data, SystemRole.class);
        getBaseMapper().insert(role);
        /*role.setCode(StrHelper.getOrDef(data.getCode(), codeGenerate.next()));
        role.setReadonly(false);
        save(role);

        saveRoleOrg(userId, role, data.getOrgList());

        cacheChannel.set(CacheKey.ROLE, String.valueOf(role.getId()), role);*/
    }
}
